package com.hspedu.generic;

import java.util.ArrayList;

/**
 * @author DL5O
 * @version 1.0
 */
@SuppressWarnings("all")
public class Generic01 {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add(new Dog("旺财",5));
        list.add(new Dog("发财",1));
        list.add(new Dog("小黄",6));
        list.add(new Cat("招财猫",8));//加入一只猫
        //遍历
        for (Object o :list) {
            Dog dog = (Dog)o;//向下转型
            System.out.println("name=" + dog.getName() + ",age=" + dog.getAge());
        }

    }
}

class Dog{
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}

class Cat{
    private String name;
    private int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}
